package com.lwj.liwanjia.adapter;

import android.content.Context;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.lwj.liwanjia.R;
import com.superrecycleview.superlibrary.adapter.BaseViewHolder;
import com.superrecycleview.superlibrary.adapter.SuperBaseAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * 所有图片
 */

public class AllAlbumAdapter extends SuperBaseAdapter<String> {
    private Context mContext;
    public List<String> selectList = new ArrayList<>();

    public List<String> getSelectList() {
        return selectList;
    }

    public AllAlbumAdapter(Context context, List<String> data) {
        super(context, data);
        this.mContext = context;
    }

    @Override
    protected void convert(BaseViewHolder holder, final String item, int position) {
        Glide.with(mContext).load(item).override(200, 300).into((ImageView) holder.getView(R.id.image));
        final CheckBox checkBox = holder.getView(R.id.check);
        ImageView imageView = holder.getView(R.id.image);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (checkBox.isChecked()) {
                    checkBox.setChecked(false);
                    for (int i = 0; i < selectList.size(); i++) {
                        if (selectList.get(i).equals(item)) {
                            selectList.remove(i);
                        }
                    }
                } else {
                    checkBox.setChecked(true);
                    selectList.add(item);
                }
            }
        });
    }

    @Override
    protected int getItemViewLayoutId(int position, String item) {
        return R.layout.all_album_item;
    }
}
